package com.example.xxpk.controller.userprops;

import com.example.xxpk.bo.UserPropsInfo;
import com.example.xxpk.common.result.R;
import com.example.xxpk.service.userprops.IUserPropsService;
import com.example.xxpk.vo.PropsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangguihong
 * @since 2025-02-13
 */
@RestController
@RequestMapping("/userProps")
@RequiredArgsConstructor
@Api(tags="用户道具表")
public class UserPropsController {


    private final IUserPropsService userPropsService;


    @GetMapping("/getUserProp")
    @ApiOperation("获取可用的道具信息")
    public R getUserPropsInfo(@RequestParam Integer userId) {
        List<UserPropsInfo> userPropsInfoList = userPropsService.getUserPropsInfoByUserId(userId);
        return R.data("获取用户道具信息成功",userPropsInfoList);
    }

    @PostMapping("/obtain")
    @ApiOperation("新增用户道具")
    public R obtainProps(@RequestBody PropsVo propsVo) {
        boolean result = userPropsService.obtainProps(propsVo.getUserId(), propsVo.getPropsId(), propsVo.getPropsCount());
        if (result) {
            return R.ok("获得道具成功");
        } else {
            return R.error("获得道具失败");
        }
    }


    @PostMapping("/use")
    @ApiOperation("用户使用道具")
    public R useProps(@RequestBody PropsVo propsVo) {
        boolean result = userPropsService.useProps(propsVo.getUserId(), propsVo.getPropsId(), propsVo.getPropsCount());
        if (result) {
            return R.ok("使用道具成功");
        } else {
            return R.error("使用道具失败，可能是未拥有该道具或数量不足");
        }
    }
}
